﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MeTV.MediaPortalService;

namespace MeTV
{
    class Channel
    {
        public WebChannel WebChannel { get; set; }
        public WebProgram[] Programs { get; set; }

        public int ID { get { return WebChannel.idChannel; } }
        public string Name { get { return WebChannel.displayName; } }

        public WebProgram CurrentProgram
        {
            get
            {
                WebProgram result = null;
                if (Programs != null)
                {
                    IEnumerable<WebProgram> currentPrograms = Programs.Where(x => x.startTime < DateTime.Now && x.endTime > DateTime.Now);
                    if (currentPrograms.Count() > 0)
                    {
                        result = currentPrograms.First();
                    }
                }
                return result;
            }
        }

        public string CurrentEpgEventTitle
        {
            get
            {
                WebProgram program = CurrentProgram;
                return program == null ? "Not available" : program.Title;
            }
        }
    }
}
